class Solution
{
public:
    vector<int> diStringMatch(string s)
    {
        int minVal = 0;
        int maxVal = 0;
        vector<int> result{0};
        for (char c : s)
        {
            if (c == 'I')
            {
                ++maxVal;
                result.push_back(maxVal);
            }
            else
            {
                --minVal;
                result.push_back(minVal);
            }
        }
        for (int &num : result)
        {
            num -= minVal;
        }
        return result;
    }
};